route.ts

route.ts

基本信息

  • 类型: API 路由
  • 路径: ./src/app/api/prompts/[id]/route.ts
  • 路由: /api/prompts/[id]

概述

单个 Prompt 的详情、更新和删除接口。支持获取 Prompt 详情、更新内容、软删除 Prompt。

HTTP 方法

  • GET: 获取 Prompt 详情
  • PATCH: 更新 Prompt
  • DELETE: 软删除 Prompt

路径参数

参数类型必填说明
idstringPrompt ID

GET - 获取 Prompt 详情

响应

成功 (200)

{
  "id": "prompt_id",
  "title": "Prompt 标题",
  "slug": "prompt-title",
  "description": "描述",
  "content": "内容",
  "type": "TEXT",
  "author": { ... },
  "category": { ... },
  "tags": [ ... ],
  "versions": [ ... ],
  "voteCount": 10,
  "hasVoted": true
}

未找到 (404)

{
  "error": "not_found",
  "message": "Prompt not found"
}

私有访问限制 (403)

{
  "error": "forbidden",
  "message": "This prompt is private"
}

PATCH - 更新 Prompt

Body 参数

参数类型必填说明
titlestring新标题
descriptionstring新描述
contentstring新内容
typeenum类型: TEXT, IMAGE, VIDEO, AUDIO, SKILL
structuredFormatenum结构化格式
categoryIdstring分类 ID(null 表示移除)
tagIdsstring[]标签 ID 数组
contributorIdsstring[]贡献者 ID 数组
isPrivateboolean是否私有
mediaUrlstring媒体 URL
bestWithModelsstring[]最佳模型
bestWithMCPobject[]MCP 配置
workflowLinkstring工作流链接

响应

成功 (200)

返回更新后的完整 Prompt 对象

错误

未授权 (401)
{
  "error": "unauthorized",
  "message": "You must be logged in"
}
无权限 (403)
{
  "error": "forbidden",
  "message": "You can only edit your own prompts"
}
验证失败 (400)
{
  "error": "validation_error",
  "message": "Invalid input"
}

DELETE - 软删除 Prompt

删除权限规则

  • 管理员: 可以删除任何 Prompt
  • 所有者: 只能删除自己因质量问题被下架的 Prompt

响应

成功 (200)

{
  "success": true,
  "message": "Prompt soft deleted"
}

错误

无权限 (403)
{
  "error": "forbidden",
  "message": "Prompts are released under CC0 and cannot be deleted. Contact an admin if there is an issue."
}
已删除 (400)
{
  "error": "already_deleted",
  "message": "Prompt is already deleted"
}

依赖

  • next/server - Next.js 服务器组件
  • next/cache - 缓存重新验证
  • zod - 输入验证
  • @/lib/auth - 认证
  • @/lib/db - Prisma 数据库客户端
  • @/lib/ai/embeddings - AI 嵌入生成
  • @/lib/slug - Slug 生成
  • @/lib/ai/quality-check - 质量检查

权限

  • GET: 公开访问(私有 Prompt 仅作者可访问)
  • PATCH: 仅作者或管理员
  • DELETE: 管理员 或 Prompt 所有者(仅针对因质量问题被下架的 Prompt)

注意事项

  1. 更新标题会自动重新生成 slug
  2. 内容变更会自动创建新版本
  3. 内容变更会触发质量检查和嵌入重新生成
  4. 删除是软删除(设置 deletedAt 字段)
← 返回目录